package com.weds.data_sync.controller;

import com.weds.data_sync.pojo.dto.DataSyncDbInfoDTO;
import com.weds.data_sync.pojo.dto.PageDto;
import com.weds.data_sync.pojo.entity.DataSyncDbInfoDO;
import com.weds.data_sync.service.DbInfoService;
import com.weds.data_sync.util.JsonData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 数据同步-数据库信息 前端控制器
 * </p>
 *
 * @author lhw
 * @since 2023-12-29
 */
@Tag(name = "数据库信息")
@RestController
@RequestMapping("/api/db_info/v1")
public class DbInfoController {

    @Autowired
    private DbInfoService dbInfoService;

    @Operation(summary = "增加数据库")
    @PostMapping("/add")
    public Integer add(@Validated @RequestBody DataSyncDbInfoDTO dataSyncDbInfoDTO) {
        return dbInfoService.add(dataSyncDbInfoDTO);
    }

    @Operation(summary = "删除数据库记录")
    @PostMapping("/del")
    public Integer del(@RequestBody DataSyncDbInfoDTO dataSyncDbInfoDTO) {
        return dbInfoService.del(dataSyncDbInfoDTO.getIds());
    }

    @Operation(summary = "修改数据库记录")
    @PostMapping("/update")
    public Integer update(@Validated @RequestBody DataSyncDbInfoDTO dataSyncDbInfoDTO) {
        return dbInfoService.update(dataSyncDbInfoDTO);
    }

    @Operation(summary = "分页查询数据库信息")
    @PostMapping("/query")
    public JsonData.PageData<DataSyncDbInfoDO> queryData(@Validated @RequestBody PageDto pageDto) {
        return dbInfoService.queryData(pageDto);
    }
}
